home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Pascal / Snippets / vListMngr 1.0 / Sources ƒ / vListDemo_Events < prev    next >
Encoding:
Text File  |  1996-04-10  |  5.4 KB  |  143 lines  |  [TEXT/PJMM]

  1. unit vListDemo_Events;
  2.  
  3. interface
  4.     uses
  5.         vListMngr, vListDemo_Globals, DemoList_Window, DemoList_Procs, InitTheMenus, HandleTheMenus;
  6.  
  7.     procedure HandleEvents (var doneFlag: BOOLEAN);
  8.  
  9. implementation
  10.     var                                 {Main variables}
  11.         myEvent: EventRecord;      {Event record for all events}
  12.         code: integer;                 {Determine event type}
  13.         whichWindow: WindowPtr;   {See which window for event}
  14.         tempRect, OldRect: Rect;        {Rect for dragging}
  15.         mResult: longint;              {Menu list and item selected values}
  16.         theMenu, theItem: integer;    {Menu list and item selected}
  17.         chCode: integer;               {Key code}
  18.         ch: char;                          {Key pressed in Ascii}
  19.         myPt: Point;                     {Temp Point, used in Zoom}
  20.         dummy: BOOLEAN;
  21.  
  22.     procedure DoMouseDown;
  23.         var
  24.             dH, dV: INTEGER;
  25.     begin
  26.         if (code = inMenuBar) then{See if a menu selection}
  27.             begin{Get the menu selection and handle it}
  28.                 mResult := MenuSelect(myEvent.Where);{Do menu selection}
  29.                 theMenu := HiWord(mResult);{Get the menu list number}
  30.                 theItem := LoWord(mResult);{Get the menu list item number}
  31.                 Handle_My_Menu(doneFlag, theMenu, theItem, activeTE);{Handle the menu}
  32.             end;{End of inMenuBar}
  33.  
  34.         if (code = InDrag) then{See if in a window drag area}
  35.             begin{Do dragging the window}
  36.                 tempRect := screenbits.bounds;{Get screen area,  l,t,r,b, drag area}
  37.                 SetRect(tempRect, tempRect.Left + 10, tempRect.Top + 25, tempRect.Right - 10, tempRect.Bottom - 10);{}
  38.                 DragWindow(whichWindow, myEvent.where, tempRect);{Drag the window}
  39.             end;{End of InDrag}
  40.  
  41.         if ((code = inGrow) and (whichWindow <> nil)) then
  42.             begin{Handle the growing}
  43.                 SetPort(whichWindow);
  44.                 myPt := myEvent.where;
  45.                 GlobalToLocal(myPt);
  46.                 OldRect := WhichWindow^.portRect;
  47.                 with screenbits.bounds do{use the screens size}
  48.                     SetRect(tempRect, 15, 15, (right - left), (bottom - top) - 20);{l,t,r,b}
  49.                 mResult := GrowWindow(whichWindow, myEvent.where, tempRect);        {Grow it}
  50.                 if mResult <> 0 then
  51.                     begin
  52.                         SetRect(tempRect, 0, 0, LoWord(mResult), HiWord(mResult));                {l,t,r,b}
  53.                         EraseRect(tempRect);
  54.                         SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);    {Resize to result}
  55.                         SetPt(myPt, whichWindow^.portRect.right, whichWindow^.portRect.bottom);
  56.                         SetRect(tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15); {Position for horz scrollbar area}
  57.                         EraseRect(tempRect);
  58.                         InvalRect(tempRect);                                                    {Flag us to update it}
  59.                         SetRect(tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15);    {Position for vert scrollbar area}
  60.                         EraseRect(tempRect);
  61.                         InvalRect(tempRect);                                                    {Flag us to update it}
  62.     {figure out how much window has changed}
  63.                         dH := (OldRect.right - OldRect.left) - LoWord(mResult);
  64.                         dV := (OldRect.bottom - OldRect.top) - HiWord(mResult);
  65.                         vLInsetList(dH, dV, DemoList);    {}
  66.                         DrawGrowIcon(whichWindow);{Draw the grow Icon again}
  67.                     end;        {if mResult <> 0}
  68.             end;        {End of growing}
  69.  
  70.         if (code = inContent) then
  71.             begin        {Handle the hit inside a window}
  72.                 if (whichWindow <> FrontWindow) then
  73.                     SelectWindow(whichWindow)
  74.                 else
  75.                     begin
  76.                         myPt := myEvent.where;
  77.                         GlobalToLocal(myPt);
  78.                         dummy := vLClick(myPt, myEvent.modifiers, DemoList);
  79.                     end;
  80.             end;        {inContent}
  81.  
  82.         if (code = inSysWindow) then{See if a DA selection}
  83.             SystemClick(myEvent, whichWindow);{Let other programs in}
  84.     end;        {MouseDown}
  85.  
  86.     procedure HandleEvents (var doneFlag: BOOLEAN);
  87.     begin
  88.         if (activeTE <> nil) then{See if a TE is active}
  89.             TEIdle(activeTE);       {Blink the cursor if everything is ok}
  90.         SystemTask;                 {For support of desk accessories}
  91.  
  92.         if GetNextEvent(everyEvent, myEvent) then{If event then...}
  93.             begin                   {Start handling the event}
  94.                 code := FindWindow(myEvent.where, whichWindow);{Get which window the event happened in}
  95.                 case myEvent.what of{Decide type of event}
  96.                     MouseDown:         {Mouse button pressed}
  97.                         DoMouseDown;
  98.                     KeyDown, AutoKey:
  99.     {either a menu key or a TE entry}
  100.                         begin
  101.                             with myevent do
  102.                                 begin
  103.                                     chCode := BitAnd(message, CharCodeMask);
  104.                                     ch := CHR(chCode);{Change to ASCII}
  105.                                     theMenu := 0;
  106.                                     if (Odd(modifiers div CmdKey)) then
  107.                                         begin{}
  108.                                             mResult := MenuKey(ch);
  109.                                             theMenu := HiWord(mResult);
  110.                                             theItem := LoWord(mResult);
  111.                                         end;    {CmdKey}
  112.                                     if (theMenu <> 0) then
  113.                                         Handle_My_Menu(doneFlag, theMenu, theItem, activeTE)
  114.                                     else
  115.                                         begin
  116.                                             if (whichWindow = DemoListWindow) then
  117.                                                 vLKey(ch, modifiers, DemoList, TheListScrap);
  118.                                         end;    {theMenu = 0}
  119.                                 end;    {with MyEvent}
  120.                         end;    {End for KeyDown,AutoKey}
  121.  
  122.                     UpDateEvt:         {Update event for a window}
  123.                         begin           {Handle the update}
  124.                             whichWindow := WindowPtr(myEvent.message);
  125.                             BeginUpdate(whichWindow);
  126.                             Update_DemoList_Window(whichWindow);{Update this window}
  127.                             EndUpdate(whichWindow);{Return to normal clipping area}
  128.                         end;            {End of UpDateEvt}
  129.  
  130.                     ActivateEvt:       {Window activated event}
  131.                         begin           {Handle the activation}
  132.                             whichWindow := WindowPtr(myevent.message);
  133.                             if odd(myEvent.modifiers) then    {Make sure it is Activate and not DeActivate}
  134.                                 begin
  135.                                     SelectWindow(whichWindow);
  136.                                     if GetWRefCon(whichWindow) > 0 then
  137.                                         DrawGrowIcon(whichWindow);
  138.                                 end;
  139.                         end;       {End of ActivateEvt}
  140.                 end;       {End of case}
  141.             end;        {end of GetNextEvent}
  142.     end;        {procedure HandleEvents}
  143. end.    {End of the unit}